package common;


import java.util.Map;
import java.util.Set;

/**
 * Created by wzl on 19-12-11.
 */
public class TSRecord extends Record{
    private String measurement=null;
    private long time;
    private Map<String,String> tags=null;
    private Map<String,Float> fields=null;

    public TSRecord(String tableName,long timeStamp, Map<String,String> tags, Map<String,Float> fields) {
        this.measurement=tableName;
        this.time =timeStamp;
        this.tags=tags;
        this.fields=fields;
    }

    public String getMeasurement() {
        return measurement;
    }

    public void setMeasurement(String measurement) {
        this.measurement = measurement;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public Map<String, String> getTags() {
        return tags;
    }

    public void setTags(Map<String, String> tags) {
        this.tags = tags;
    }

    public Map<String, Float> getFields() {
        return fields;
    }

    public void setFields(Map<String, Float> fields) {
        this.fields = fields;
    }

    public String toString(){
        StringBuilder str=new StringBuilder();
        str.append("{").append("\"fields\":{");

        Set<String>  fieldKeys=fields.keySet();
        for(String key: fieldKeys){
            str.append("\""+key+"\":").append(fields.get(key)).append(",");
        }
        str.deleteCharAt(str.length()-1);
        str.append("},");

        str.append("\"tags\":{");
        Set<String> tagKeys=tags.keySet();
        for(String key:tagKeys){
            str.append("\""+key+"\":").append("\""+tags.get(key)+"\"").append(",");
        }
        str.deleteCharAt(str.length()-1);
        str.append("},");

        str.append("\"measurement\":"+"\""+measurement+"\",");
        str.append("\"time\":").append(time*1000000).append("}");

        return str.toString();
    }
}
